<?php
namespace App\Models;

//use App\Events\UserRegistered;

use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;


class User extends Authenticatable implements JWTSubject

{
    use Notifiable;

    protected $table = 'users';
    protected $primaryKey = 'id';
    public $timestamps = true;
    const CREATED_AT = 'create_at';
    const UPDATED_AT = 'update_at';

    protected $guarded = [

    ];

    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];


//    public static function boot()
//    {
//        parent::boot();
//        static::created(function (User $user) {
//            \event(new UserRegistered($user));
//        });
//    }

    public function setPasswordAttribute($value)
    {
        //将密码进行加密
        $this->attributes['password'] = bcrypt($value);
    }

    public function platform()
    {
        return $this->hasOne('App\Models\UserPlatform', 'uid', 'id');
    }

    /**JWT**/
    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
    /**JWT---End**/
}
